install.packages("forecast")
library(forecast)

setwd("I:\\Staff\\Clients\\Demirel-Pegg, Tijen\\August 2015")
data <- read.csv("temp4.csv", header=T)
head(data)
attach(data)
names(data)
nrow(data)
#p3 (CE) and p5 (COOPT) are out of sample
#p2 (CE) and p4 (COOPT) are in sample
#protcamp is observed data

p2[233]
insamp <- data[1:232,]
outsamp <- data[233:345,]

outsamp[1,]
outsamp$p3[1]
head(outsamp)
outsamp$protcamp[1]

nrow(outsamp)
outsamp$protcamp <- outsamp$protcamp + 0.00001
num=0
denom=0
for(i in 1:112){
numtemp = ((outsamp$p3[i+1] - outsamp$protcamp[i+1])/outsamp$protcamp[i])^2
denomtemp = ((outsamp$protcamp[i+1] - outsamp$protcamp[i])/outsamp$protcamp[i])^2
num = num + numtemp
denom = denom+denomtemp
}
u <- sqrt(num/denom)
u



outsamp$protcamp <- outsamp$protcamp + 0.1
num=0
denom=0
for(i in 1:112){
numtemp = ((outsamp$p5[i+1] - outsamp$protcamp[i+1])/outsamp$protcamp[i])^2
denomtemp = ((outsamp$protcamp[i+1] - outsamp$protcamp[i])/outsamp$protcamp[i])^2
num = num + numtemp
denom = denom+denomtemp
}
u <- sqrt(num/denom)
u







temp <- accuracy(outsamp$p5, outsamp$protcamp)
summary(temp)